'use strict';

const Service = require('egg').Service;

class banners extends Service {
  async findAll() {
    const result = await this.app.mysql.select('banners');
    return {
      code: 200,
      msg: '查找成功',
      data: result,
    };
  }
  async find(uid) {
    const result = await this.app.mysql.get('banners', { id: uid });
    if (result !== null) {
      return {
        code: 200,
        msg: '查找成功',
        data: result,
      };
    }
    return {
      msg: '没有此条数据！',
    };
  }

  
  async create(params) {
    console.log(params)
    const cfg = {
     ...params
    };
    const result = await this.app.mysql.insert('banners', cfg);
    return {
      code: 200,
      msg: '创建成功',
      data: result,
    };
  }
  async delete(uid) {
    console.log(uid)
    const result = await this.app.mysql.delete('banners', { id: uid });
    return {
      code: 200,
      msg: '删除成功',
      data: result,
    };
  }
  async update(uid, params) {
    console.log(params)
    const cfg = {
      id: uid,
      ...params
    };
    const result = await this.app.mysql.update('banners', cfg);
    return {
      code: 200,
      msg: '更新成功',
      data: result,
    };
  }
  async findAll0(pass) {
    const result = await this.app.mysql.select('banners', {
      where: { pass },
    });
    return {
      code: 200,
      msg: '查找成功',
      data: result,
    };
  }
}

module.exports = banners;
